home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Ultimate Windows Set
/
The Ultimate Windows Set.iso
/
win
/
pro289
/
readme.pok
< prev
next >
Wrap
Text File
|
1993-12-17
|
10KB
|
247 lines
Visual Basic Video Poker By Dan Mullin, 72644,2423
In this archive you will find both the source code and a compiled version of
Windows Video Poker, along with 53 .BMP files. No, it will not pay you back if
you win but, then again, you don't have to pump it full of dollar tokens either!
As simple as this game is, I loaded it for a different reason then to simply
provide a little midday diversion. If you enjoy card games like I do, you will
find some very important and worthwhile procedures included in this code.
SHUFFLING:
The typical routine for creating a deck of shuffled cards is to generate an
array of 52 unique random numbers ranging from 0 to 51, i.e.:
Dim Deck(51) As Integer
Dim Collision As Integer
'Collision is the detection of a repeated number
Randomize
For Index = 0 To 51
Collision = True
Do Until Not Collision
Deck(Index) = Int(51 * Rnd + 1)
Collision = False
If Index > 0 Then
For Index2 = 0 To Index - 1
If Deck(Index2) = Deck(Index) Then
Collision = True
End If
Next Index2
End If
Loop
Next Index
You use this number as an index to find the specific card, i.e., 0, A of Clubs,
1, 2 of Clubs...50, Q of Spades, 51, K of Spades.
What's the problem? As you can see, the first few numbers are generated fairly
quickly. However, as the size of the deck increases, the search for a repeated
number, a collision, gets longer and the possiblities of generating a repeated
number becomes greater as more numbers are entered into the array and fewer
unique numbers are left!
The SHUFFLE procedure in VPOK.BAS approaches this problem from a different
angle. When you open a new deck of cards they are all in order. You then mix
them up. The SHUFFLE routine also places all of the cards in order. The record
for a card contains its value (1=A, 13=K), its suit(0=Clubs, 1=Diamonds,
2=Hearts, 3=Spades), and its number in the deck (0=A Of Clubs, 1=2 Of Clubs...
50=Q Of Spades, 51=K Of Spades). It also contains a variable we will call POS.
POS is assigned a random value as each card is assigned its ordered values.
We then have 52 cards in order, each holding a totally unordered POS variable.
We then sort the deck by the POS variable, creating a deck of unordered cards
with their POS variables in order! What if a POS value is repeated? The sort
routine doesn't care. It simply leaves the two cards in order. Ta-Da, the deck
is shuffled!
You will notice that we add 1 to the value of the card, i.e., A<>0, A=1 and
2<>1,2=2. Why? If you create a game that uses scoring for the cards the scoring
normally is consistant with the card value. A 3 usually equals 3 points!
Some games may require more than one deck. NO PROBLEM! Just increase your
DeckSize to 103, 154, whatever, and place multiple sets of ordered decks into
the array using MOD 52 as shown.
CARD GRAPHICS:
I have included a set of .BMP files for each card in the deck, plus one card
back. If they look familiar I will confess that I copied them out of the .EXE
file for Solitaire (Hope I didn't violate copyrights!) When I create a cardgame
one of the first things I do is create a control array of 53 picture boxes,
i.e., Picture1(0)-Picture1(52), and load all of the bitmaps into them in order
according to the card's number in the deck (0=A Of Clubs...51=K Of Spades,
52=card back ). I keep this array of picture boxes hidden so they are not
displayed on the form. This makes the final program bigger but speeds and
simplifies the process of displaying the cards. Once loaded, all I have to do
is pass the Picture property of the deck card to the picture box where I want
to display the card. For example:
Picture2 is a visible picture box
Picture1() is the invisible array of picture boxes containing the deck.
Picture2.Picture = Picture1(3).Picture
This will copy the graphic for the fourth card (we start at 0) in the deck to
the picture box where I want the card to be displayed.
In your code it will typically look like this:
Picture2.Picture = Picture1(Deck(CardYouWant).CardNum).Picture
You DO NOT have to make more than one array of Picture1() if your program uses
more than one deck! The shuffle routine produced multiple copies of the same
deck and, though the positions in the array go from 0 to DeckSize, the CardNum
values go from 0 to 51 for the first deck, then repeat 0 to 51 for each deck
that follows.
PARSING A HAND:
Though this procedure in VPOK.FRM is poker specific, it may give you some ideas
on how to efficiently analyze a hand. We basically have 9 possible winning hands
in Video Poker. We assign an integer to these winning hands as follows and
return it to see if we won:
Royal Flush = 9
Straight Flush = 8
Four Of A Kind = 7
Full House = 6
Flush = 5
Straight = 4
Three Of A Kind = 3
Two Pair = 2
Jacks Or Better = 1
First we check for a Flush, i.e., all cards of the same suit. This is easy! Set
Flush = True, then cycle through the hand to see if any of the card suits are
not equal. If not equal, change Flush = False.
Next we check for a Straight, i.e., all cards in numerical order. To simplify
this check (and the rest of the checks) we sort the hand according to the card
value (1=A, 13=K). So we can manipulate these values without corrupting the
hand, we copy them over to a temporary array, V(4), which holds only these
values. We don't care about the suit anymore. All we are concerned with is their
numerical values. See the Hand_Sort procedure.
Since our cards are now in numerical order, a Straight can be detected if each
card has a value one less than the next card in the hand. We set Straight = True
and loop through comparing values, CardVal(Index) + 1 = CardVal(Index + 1).
If any of these checks fail, we set Straight = False.
We have one special case for a Straight. The Ace can either be before a 2 or
after a King. Since an Ace has a value of 1 it won't be placed after the King
when sorted and we could miss a 10,J,Q,K,A straight. Ahh, but we have the V(4)
array that we can change without screwing up our original hand. We check to see
if the first card is a "1", i.e., a "low" Ace. If so, we copy all of the cards
down one position and make the last card a 14, a "high" Ace. We then check for
a Straight once more. If we have a 10,J,Q,K,A straight the card values will be
10,11,12,13,14 and it will be detected.
We then look for Straight Flushes and Royal Flushes. If Straight = True and
Flush = True and the first card, V(0), is a 10, we have a Royal Flush. Remember
that the Ace will be at the top in a 10,J,Q,K,A straight. If the first card is
not a 10, we have a Straight Flush. Otherwise, we have a Straight, a Flush, or
Nothing. If we have Nothing at this point we go on.
We reassign the original card values back to V(4) since we may have changed them
when doing the check for a 10-A straight. The next chunk of code may seem
convoluted but it is actually a very efficient method of checking for the
remaining possible winning hands.
We take our copy of the hand, V(4), and look at the first four cards in order.
If the card equals the next card in the hand, we keep its value. Otherwise we
make it 0. We then make the last card = 0. For example:
Hand 23359
Result 03000
Hand 34499
Result 04090
We create a second array, P(2), of three integers and a counter called SameVal.
We loop through our V(4) array again. If the card <> 0 then we copy it to
P(SameVal) and increment SameVal by one. From the above example:
Result 04090
P(0),P(1) 49
SameVal 2
Believe me, it's easier than trying to cover every possible combination looking
at the full hand. This way we toss all of the cards that can have no impact on
the result and concentrate on the cards that do have an effect! We now have
everything we need to determine all of the other winning combinations. Look at
these examples:
Hand 24578
Result 00000
SameVal 0
If SameVal = 0 then we have Nothing.
Hand 23379
Result 03000
P(0) 3
SameVal 1
If SameVal = 1 then we have one Pair. If P(0) > 10 then the pair is Jacks Or
Better.
Hand 45556
Result 05500
P(0),P(1) 55
SameVal 2
If SameVal = 2 and P(0) = P(1) then we have Three Of A Kind.
Hand 33699
Result 30090
P(0),P(1) 39
SameVal 2
If SameVal = 2 and P(0) <> P(1) then we have Two Pair.
Hand 24444
Result 04440
P(0),P(1),P(2) 444
SameVal 3
If SameVal = 3 and P(0) = P(1) = P(2) we have Four Of A Kind
Hand 33555
Result 30550
P(0),P(1),P(2) 355
SameVal 3
If SameVal = 3 and P(0), P(1), and P(2) are not all equal we have a Full House.
Not Bad, Ehhhh?
SUMMARY:
Along with a fully functional game, you now have some of the tools needed to
create your own card games. If you use these procedures all I ask is that you
include a little note in your splash screen or code like:
"Shuffle" Procedure By Dan Mullin
It simply lets me know that someone finds this work of value. And let me know if
you DO create a program using these procedures. My ID is 72644,2423.
Don't distribute this code or the complete program for money! Just give it away!
Bang on it, beat it, change it, screw it up! I don't care! HAVE FUN!
Dan Mullin
72644,2423